//
//  UIView+XJCategory.m
//  TranslateSoftware
//
//  Created by boniu on 2022/5/9.
//

#import "UIView+XJCategory.h"
#import "UIView+LFZExtension.h"

@implementation UIView (XJCategory)

+ (UIWindow *)getCurrentWindos {
    
    for (UIWindow * win in [UIApplication sharedApplication].windows) {
        if (win.isKeyWindow == true) {
            return win;
        }
    }
    return [[UIApplication sharedApplication].windows lastObject];
}

//返回当前view 相对 win 的位置
- (CGRect)getToWinPoint{
    UIWindow *win = [UIView getCurrentWindos];
    CGRect rect = [win convertRect:CGRectMake(0, 0, self.width, self.height) fromWindow:win];
    return rect;
}

//单击
- (void)addTapGesture:(nullable id)target action:(SEL)action {
    
    // 添加轻击手势
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:target action:action];
    tapGesture.numberOfTapsRequired = 1; // 设置手势次数
    tapGesture.numberOfTouchesRequired = 1; // 设置手指个数
    [self addGestureRecognizer:tapGesture];
}

//双击
- (void)addTapGesture2:(nullable id)target action:(SEL)action {
    
    // 添加轻击手势
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:target action:action];
    tapGesture.numberOfTapsRequired = 2; // 设置手势次数
    tapGesture.numberOfTouchesRequired = 1; // 设置手指个数
    [self addGestureRecognizer:tapGesture];
}


//长按
- (void)addTapLongGesture:(nullable id)target action:(SEL)action {
    
    // 添加轻击手势
    UILongPressGestureRecognizer *longPan = [[UILongPressGestureRecognizer alloc] initWithTarget:target action:action];
    [self addGestureRecognizer:longPan];
}


//圆角
- (void)setCornerRadius:(CGFloat)size {
    self.layer.cornerRadius = size;
    self.layer.masksToBounds = true;
}

//指定的圆角
- (void)setCornerRadiusCustom:(UIRectCorner)corners size:(CGFloat)size {

    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(size, size)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.bounds;
    maskLayer.path = maskPath.CGPath;
    self.layer.mask = maskLayer;
}

//描边
- (void)setBorder:(CGFloat)size color:(UIColor *)color {
    
    self.layer.borderColor = color.CGColor;
    self.layer.borderWidth = size;
}

//设置阴影
- (void)setShadowColor:(UIColor *)color {
    
    self.layer.shadowColor = color.CGColor;
    self.layer.shadowOpacity = 0.2;
    self.layer.shadowRadius = 5;
    self.layer.shadowOffset = CGSizeMake(0, 0);
}

//设置阴影
- (void)setShadowColor1:(UIColor *)color {
    
    self.layer.shadowColor = color.CGColor;
    self.layer.shadowOpacity = 0.2;
    self.layer.shadowRadius = 8;
    self.layer.shadowOffset = CGSizeMake(0, 0);
}

//设置阴影
- (void)setShadowColor2:(UIColor *)color {
    
    self.layer.shadowColor = color.CGColor;
    self.layer.shadowOpacity = 0.1;
    self.layer.shadowRadius = 5;
    self.layer.shadowOffset = CGSizeMake(0, 0);
}




@end
